package com.xunshangwang.pinhaohuo.widgets;

import android.content.Context;
import android.graphics.Color;
import android.graphics.PorterDuff;
import android.support.v4.content.ContextCompat;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ProgressBar;

import com.xunshangwang.pinhaohuo.R;

/**
 * Created by xzp on 15/10/9.
 */
public class LoadLayout extends FrameLayout{
    private View mLoad;
    public LoadLayout(Context context) {
        super(context);
        init();
    }

    public LoadLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }
    private void init()
    {
        mLoad = LayoutInflater.from(getContext()).inflate(R.layout.load_progress, null);
        LayoutParams params = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
        mLoad.setLayoutParams(params);
        ProgressBar progressBar = (ProgressBar) mLoad.findViewById(R.id.load_progress_bar);
        progressBar.getIndeterminateDrawable().setColorFilter(ContextCompat.getColor(getContext(),R.color.red), PorterDuff.Mode.SRC_IN);
    }


    public void startLoad()
    {
        if(mLoad.getParent()==null)
            this.addView(mLoad);
    }
    public void finishLoad()
    {
        if(mLoad.getParent()!=null)
            this.removeView(mLoad);
    }
}
